package com.hc.springbootzookeeper.config;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZookeeperClient {

    @Autowired
    private ZookeeperConfig config;

    @Bean(initMethod = "start")
    public CuratorFramework getClient(){
        return CuratorFrameworkFactory.newClient(config.getConnectString(),config.getSessionTimeoutMs(),
                config.getConnectionTimeoutMs(),
                new RetryNTimes(config.getRetryCount(),config.getElapsedTimeMs()));
    }
}
